home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / yacas_alg / yacas_morphos / share / yacas / include / lispstring.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  2.7 KB  |  78 lines

  1. /** \file lispstring.h
  2.  *  Defining a string class.
  3.  */
  4.  
  5.  
  6. #ifndef __lispstring_h__
  7. #define __lispstring_h__
  8.  
  9. #include "yacasbase.h"
  10. #include "grower.h"
  11. #include "refcount.h"
  12.  
  13. /** \class LispString : zero-terminated byte-counted string.
  14.  * Also keeps a reference count for any one interested.
  15.  * LispString is derived from CArrayGrower, so the function
  16.  * NrItems returns the length of the buffer. Since the string
  17.  * is also zero-terminated (for better interfacing with the normal
  18.  * c functions), the string length is NrItems()-1.
  19.  *
  20.  * This class also allows the string to point to a buffer which is owned
  21.  * by another part of the system, in which case it cannot be resized.
  22.  * The array will then not be freed by this class.
  23.  */
  24. class LispString : public CArrayGrower<LispChar>, public RefCountedObjectBase
  25. {
  26. public:
  27.     /** Constructor which allows the caller to specify whether
  28.      * the buffer is owned externally. Use the assignment operator
  29.      * to set the string after this.
  30.      */
  31.     inline LispString(LispBoolean aStringOwnedExternally=LispFalse);
  32.  
  33.     /// Construct from another string
  34.     inline LispString(LispString &aString,
  35.                       LispBoolean aStringOwnedExternally=LispFalse);
  36.     /** Set string from assignment. The assignment abides by earlier
  37.      * functions setting the string as owned externally.
  38.      */
  39.     inline LispString& operator=(LispCharPtr aString);
  40.     /// Construct from string.
  41.     inline LispString(LispCharPtr aString,
  42.                       LispBoolean aStringOwnedExternally=LispFalse);
  43.     /// String() returns the pointer to the first character.
  44.     inline LispCharPtr String() const;
  45.     /** String comparison. If the string is in the hash table it is faster
  46.      * to compare the pointers to the strings, since in that case if they
  47.      * are equal they should in fact be literally the same object.
  48.      */
  49.     LispInt operator==(const LispString& aString);
  50.     
  51.     /** Set string by taking part of another string. The string cannot
  52.      * be owned externally for this operation
  53.      */
  54.     void SetStringCounted(LispCharPtr aString,LispInt aLength);
  55.     /** Set string from other string, adding quotes around the string.
  56.      * The string cannot be owned externally for this operation
  57.      */
  58.     void SetStringUnStringified(LispCharPtr aString);
  59.     /** Set string from other string, removing quotes around the string.
  60.      * The string cannot be owned externally for this operation
  61.      */
  62.     void SetStringStringified(LispCharPtr aString);
  63.  
  64. private:
  65.     void SetString(LispCharPtr aString,
  66.                    LispBoolean aStringOwnedExternally=LispFalse);
  67.  
  68. };
  69.  
  70. #define LispStringRef LispString &
  71. #define LispStringPtr LispString *
  72.  
  73.  
  74. #include "lispstring.inl"
  75. #endif
  76.  
  77.  
  78.